define(function(require,exports,module){
	var aw = require("ajaxwrapper");
	
	module.exports = {
		getGridFetchProperties: function(){
			return "planItemGroup.pkPlanItemGroup," +
					"planItemGroup.version," +
					"signUpNumber," +
					"groupReserve.checkInDate," +
					"groupReserve.checkOutDate," +
					"planItemGroup.planItem.startDate," +
					"planItemGroup.planItem.endDate," +
					"planItemGroup.planItem.destination.pkDestination," +
					"planItemGroup.planItem.destination.name," +
					"planItemGroup.checkInStatus.*," +
					"planItemGroup.signUpRoomTypeCounts.roomType.*," +
					"planItemGroup.signUpRoomTypeCounts.*," +
					"groupReserve.pkGroupReserve," +
					"groupReserve.version," +
					"groupReserve.roomRegisters.room.code," +
					"groupReserve.roomRegisters.room.roomType.name," +
					"groupReserve.roomRegisters.room.orgBuilding.name," +
					"groupReserve.reserveDate," +
					"groupReserve.operator.name," +
					"groupReserve.description," +
					"groupReserve.allianceBuilding," +
					"groupReserve.allianceRoom," +
					"groupReserve.checkInType.*," +
					"planItemGroup.servicePoint.name," +
					"planItemGroup.allianceOrg.name," +
					"verNumber,planTitle"
		},
		procRoomDatas: function(widget,datas,type){
			var ret = {};
			var length = datas.length;
			var selectedData = widget.get("model").selectedDatas;
			var subnav = widget.get("subnav");
			var building = subnav.getValue("buildings");
			var roomType = subnav.getValue("roomTypes");
			
			var numObj = {};
			
			for(var i=0;i<length;i++){
				var checkOutDate = datas[i].checkOutDate,
					status = datas[i].room.status.key;
				
				if(checkOutDate){
					 datas[i].room.checkOutDate = moment(checkOutDate).format("MM-DD");
				}else{
					datas[i].room.checkOutDate = ""
				}
				
				if(status == "Clear" || status == "Dirty" || status == "CheckIn" || status == "Repairing"  || datas[i].isWillGo){
					var pkRoom = datas[i].room.pkRoom;
					var ifHasSelected = selectedData[roomType] ? (
							selectedData[roomType].buildings ? (
								selectedData[roomType].buildings[building].rooms ? (
									selectedData[roomType].buildings[building].rooms[pkRoom]
							) : null
							) : null) : null;
					if(ifHasSelected){
						datas[i].room.isSelected = true;
						datas[i].room.typeName = status.toLowerCase();
					}
				}
				if(status == "Clear"){
					datas[i].room.isClear = true;
				}else if(status == "Dirty"){
					datas[i].room.isDirty = true;
				}else if(status == "CheckIn"){
					datas[i].room.isCheckIn = true;
				}else if(status == "Repairing"){
					datas[i].room.isRepairing = true;
				}else if(status == "Temporary"){
					datas[i].room.isTemporary = true;
				}else if(status == "SelfUse"){
					datas[i].room.isSelfUse = true;
				}else if(status == "Free"){
					datas[i].room.isFree = true;
				}else{
				    datas[i].room.isAppoint = true;
                }
				
				if(!numObj[status.toLowerCase()]){
					numObj[status.toLowerCase()] = 1;
				}else{
					numObj[status.toLowerCase()]++;
				}

                if(datas[i].isWillGo){
                    datas[i].room.isWillGo = true;
                    if(!numObj["willgo"]){
                        numObj["willgo"] = 1;
                    }else{
                        numObj["willgo"]++;
                    }
                }
				if(datas[i].isAppoint){
					datas[i].room.isAppoint = true;
					if(!numObj["appoint"]){
						numObj["appoint"] = 1;
					}else{
						numObj["appoint"]++;
					}
				}
				
				if(!datas[i].isAppoint){
                    datas[i].room.isShow = true;
				    if(status == "CheckIn" && !checkOutDate){
                        datas[i].room.isShow = false;
                    }
				}else{
					datas[i].room.isShow = false;
				}

				ret[datas[i].room.pkRoom] = datas[i].room;
			}
			
			for(var key in numObj){
				$("#"+key+"-num",widget.element).text(numObj[key]);
			}
			return ret;
		}
	};
});